package crafex.engine.tools;


import java.util.Hashtable;
import java.util.Random;

import crafex.engine.objects.WorldObject;

import android.annotation.SuppressLint;
import android.util.FloatMath;

@SuppressLint("UseValueOf")
public class Tools {
	
	/**the savepath for the game in the android memory*/
	private static String savePath;
	/**direction for the entitys to move*/
	public static Hashtable<String, Integer> directions;
	/**randomness*/
	private static Random random;
	
	
	public Tools(String savePath){
		setSavePath(savePath);
		directions = new Hashtable<String, Integer>();
		directions.put("down", new Integer(0));
		directions.put("right", new Integer(1));
		directions.put("left", new Integer(2));
		directions.put("up", new Integer(3));
		
		random = new Random();
	}
	
	/**
	 * gets teh save path
	 * @return
	 */
	public static String getSavePath() {
		return savePath + "/";
	}

	/**
	 * sets the save path
	 * @param savePath
	 */
	public static void setSavePath(String savePath) {
		Tools.savePath = savePath;
	}
	
	/**
	 * makes the movement for the vertex to move to reach the target with in the speed provided
	 * @param vertex
	 * @param targetVertex
	 * @param speed
	 * @return movement
	 */
	public static FloatVertex2D followX(FloatVertex2D vertex, FloatVertex2D targetVertex, float speed){
		float tempX = targetVertex.getX() - (vertex.getX());
		float tempY = targetVertex.getY() - (vertex.getY());
		float distance = FloatMath.sqrt((tempX * tempX) + (tempY * tempY));
		
		FloatVertex2D data = new FloatVertex2D(0, 0);
		
		if(distance >= speed){
			data.setX((tempX / distance) * speed);
			data.setY((tempY / distance) * speed);
		}else if(distance == 0){
			
		}else{
			data.setX(tempX);
			data.setY(tempY);
		}
		
		
		return data;
	}
	
	/**
	 * returns a random int between the provided ints(including the numbers given)
	 * @param lowest
	 * @param highest
	 * @return
	 */
	public static int getRandomInt(int lowest, int highest){		
		return ((random.nextInt(highest - lowest)) + lowest);
	}
	
	public static double getRandomDouble(double lowest, double highest){
		double temp = ((highest - lowest)-1);
		double des = (int) (random.nextDouble()*100);
		des /= 100;
		
		double data = random.nextInt((int)(temp));
		data += lowest;
		data += des;
		
		return data;
	}
	
	public static WorldObject getBullet(){
		return null;
	}
}